import { getRole } from '@/utils/index'
import { cloneDeep } from 'lodash'
export default {
  namespaced: true,
  state: {
    navs: [
      {
        label: '首页',
        icon: 'Menu',
        path: '/dashBoard',
        isMenu: false,
        roles: '*'
      },
      {
        label: '学员管理',
        icon: 'Tickets',
        isMenu: true,
        roles: ['admin', 'a'],
        children: [
          {
            path: '/nowPage',
            label: '在学学员',
            roles: ['admin', 'a']
          },
          {
            path: '/wantPage',
            label: '意向学员',
            roles: ['admin', 'a']
          },
          {
            path: '/endPage',
            label: '结业学员',
            roles: ['admin']
          }
        ]
      },
      {
        label: '个人中心',
        icon: 'User',
        path: '/userInfo',
        roles: ['admin', 'a'],
        isMenu: false // 代表是否是目录
      },
      {
        label: '设置',
        icon: 'Setting',
        path: '/setting',
        roles: ['admin'],
        isMenu: false // 代表是否是目录
      }
    ]
  },
  getters: {
    auth_menus(state) {
      const navs = cloneDeep(state.navs)
      const role = getRole()
      const authMenus = []
      navs.forEach(menu => {
        if (menu.roles === '*' || menu.roles.includes(role)) {
          if (menu.isMenu) {
            menu.children.filter(subMenu => subMenu.roles === '*' || subMenu.roles.includes(role))
          }
          authMenus.push(menu)
        }
      })
      return authMenus
    }
  }
}
